package com.stx.uiscreenadtdemo;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;


public class StxLinearLayout extends LinearLayout {

	public StxLinearLayout(Context context) {
		super(context);
	}
	
   public StxLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs, 0);
    }

    public StxLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    	super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    	super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    	int childCount = getChildCount();
    	for(int i = 0; i < childCount; i ++){
    		View v = getChildAt(i);
    		LayoutParams lp = (LayoutParams)v.getLayoutParams();
    		if(lp.width == LayoutParams.MATCH_PARENT || 
    				lp.width == LayoutParams.WRAP_CONTENT){
    		}else{
    			lp.width = UIUtils.getInstance(this.getContext()).getWidth(lp.width);
    		}
       		if(lp.height == LayoutParams.MATCH_PARENT || 
    				lp.height == LayoutParams.WRAP_CONTENT){
    		}else{
    			lp.height = UIUtils.getInstance(this.getContext()).getHeight(lp.height);
    		}
    		lp.leftMargin = UIUtils.getInstance(this.getContext()).getWidth(lp.leftMargin);
    		lp.rightMargin = UIUtils.getInstance(this.getContext()).getWidth(lp.rightMargin);
    		lp.topMargin = UIUtils.getInstance(this.getContext()).getHeight(lp.topMargin);
    		lp.bottomMargin = UIUtils.getInstance(this.getContext()).getHeight(lp.bottomMargin);
    	}
    }
    
}






